<template>
  <el-container class="home-container">
    <!-- 头部 -->
    <el-header>
      <div>
        <span>猎蜂招聘后台管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <!-- 主体 -->
    <el-container>
      <!-- 左侧内容 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409EFF"
          unique-opened
          :collapse="isCollapse"
          :collapse-transition="false"
          router
          :default-active="activePath"
        >
          <!-- 一级菜单 -->
          <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id">
            <template slot="title">
              <i :class="iconsObj[item.id]"></i>
              <span>{{item.authName}}</span>
            </template>

            <!-- 二级菜单 -->
            <el-menu-item
              :index="'/'+subItem.path"
              v-for="subItem in item.children"
              :key="subItem.id"
              @click="saveNavState('/' + subItem.path)"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{subItem.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 左侧内容 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      menulist: [],
      iconsObj: {
        '101': 'el-icon-user-solid',
        '102': 'el-icon-s-tools',
        '103': 'el-icon-s-order',
        '104': 'el-icon-s-order'
      },
      // 是否折叠
      isCollapse: false,
      //激活的地址
      activePath: '/company'
    }
  },
  created() {
    this.activePath = window.sessionStorage.getItem('activePath') || '/company'
    this.go()
  },
  methods: {
    //退出登录
    logout() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    //折叠状态
    toggleCollapse() {
      this.isCollapse = !this.isCollapse
    },
    //连接的激活状态
    saveNavState(activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    },
    // 判断 用户是否 超管or 普管
    go() {
      console.log(3)
      if (this.$store.getters.iftype3) {
        console.log(2)
        this.menulist = [
          {
            id: 101,
            authName: '账号管理',
            path: 'admin',
            children: [
              {
                id: 112,
                authName: '修改密码',
                path: 'password',
                children: []
              }
            ]
          },
          {
            id: 104,
            authName: '公司管理',
            path: 'company',
            children: [
              {
                id: 142,
                authName: '我的公司',
                path: 'company',
                children: []
              },
              {
                id: 143,
                authName: '公司岗位',
                path: 'position',
                children: []
              }
            ]
          }
        ]
      } else {
        this.menulist = [
          {
            id: 101,
            authName: '账号管理',
            path: 'admin',
            children: [
              {
                id: 111,
                authName: '管理员列表',
                path: 'admin',
                children: []
              },
              {
                id: 112,
                authName: '修改密码',
                path: 'password',
                children: []
              }
            ]
          },
          {
            id: 102,
            authName: '页面管理',
            path: 'pagemanage',
            children: [
              {
                id: 121,
                authName: '修改页面',
                path: 'pagemanage',
                children: []
              }
            ]
          },
          {
            id: 103,
            authName: '人才库',
            path: 'user',
            children: [
              {
                id: 131,
                authName: '人才库列表',
                path: 'user',
                children: []
              }
            ]
          },
          {
            id: 104,
            authName: '公司管理',
            path: 'company',
            children: [
              {
                id: 141,
                authName: '所有公司',
                path: 'all',
                children: []
              },
              {
                id: 142,
                authName: '我的公司',
                path: 'company',
                children: []
              },
              {
                id: 143,
                authName: '公司岗位',
                path: 'position',
                children: []
              }
            ]
          }
        ]
      }
    }
  }
}
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}
.el-aside {
  background-color: #333744;
  .el-menu {
    border-right: none;
  }
}
.el-main {
  background-color: #eaedf1;
}
.iconfont {
  margin-right: 10px;
}
.toggle-button {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
</style>